<?php

/**
 * AmplifyCMS
 *
 * This file is part of AmplifyCMS.
 *
 * AmplifyCMS is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * AmplifyCMS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author Rodrigo Rutkoski Rodrigues, <rutkoski@gmail.com>
 * @copyright Copyright 2008 Rodrigo Rutkoski Rodrigues
 */

/**
 *
 */
class UsersActionsHelper extends AmpCommonActionsHelper
{

  /**
   *
   */
  public function __construct()
  {
    parent::__construct('/users');
  }

  /**
   *
   */
  protected function buildIndexLink()
  {
    return Simplify::getInstance()->getUser()->can('/users') ? parent::buildIndexLink($this->route) : '';
  }

  /**
   *
   */
  protected function buildViewLink($user)
  {
    return Simplify::getInstance()->getUser()->can('/users/view/' . $user->get('id')) ? parent::buildViewLink($user) : '';
  }

  /**
   *
   */
  protected function buildEditLink($user)
  {
    if (Simplify::getInstance()->getUser()->hasLevel($user->getMinLevel() - 1) || Simplify::getInstance()->getUser()->id == $user->id) {
      return parent::buildEditLink($user);
    }
    
    return '';
  }

  /**
   *
   */
  protected function buildCreateLink()
  {
    return Simplify::getInstance()->getUser()->can('/users/create') ? parent::buildCreateLink() : '';
  }

  /**
   *
   */
  protected function buildDeleteLink($user)
  {
    if ($user->get('id') != 1 && (Simplify::getInstance()->getUser()->hasLevel($user->getMinLevel() - 1) || Simplify::getInstance()->getUser()->id == $user->id)) {
      return parent::buildDeleteLink($user);
    }
    
    return '';
  }

}

?>